package com.mriassl.stream.lib.rabbitmq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    @Bean
    public Queue bettingQueue() {
        return new Queue(RabbitMQConst.QUEUE_FOR_BETTING);
    }

    @Bean
    public Queue bettingSuccReplyQueue() {
        return new Queue(RabbitMQConst.QUEUE_FOR_BETTING_REPLY);
    }

    @Bean
    public Queue bettingFailReplyQueue() {
        return new Queue(RabbitMQConst.QUEUE_FOR_BETTING_REPLY_FAIL);
    }

    @Bean
    public Queue bettingFailNSFReplyQueue() {
        return new Queue(RabbitMQConst.QUEUE_FOR_BETTING_REPLY_FAIL_NSF);
    }

    @Bean
    public Queue revokeQueue() {
        return new Queue(RabbitMQConst.QUEUE_FOR_REVOKE);
    }

    @Bean
    public Queue revokeReplyQueue() {
        return new Queue(RabbitMQConst.QUEUE_FOR_REVOKE_REPLY);
    }

    @Bean
    TopicExchange bettingExchange() {
        return new TopicExchange(RabbitMQConst.EXCHANGE_FOR_BETTING);
    }

    @Bean
    TopicExchange revokeExchange() {
        return new TopicExchange(RabbitMQConst.EXCHANGE_FOR_REVOKE);
    }

    @Bean
    Binding bindingBettingExchange(Queue bettingQueue, TopicExchange bettingExchange) {
        return BindingBuilder.bind(bettingQueue).to(bettingExchange).with(RabbitMQConst.ROUTE_FOR_BETTING);
    }

    @Bean
    Binding bindingBettingSuccReplyExchange(Queue bettingSuccReplyQueue, TopicExchange bettingExchange) {
        return BindingBuilder.bind(bettingSuccReplyQueue).to(bettingExchange)
                .with(RabbitMQConst.ROUTE_FOR_SUCC_BETTING_REPLY);
    }

    @Bean
    Binding bindingBettingFailReplyExchange(Queue bettingFailReplyQueue, TopicExchange bettingExchange) {
        return BindingBuilder.bind(bettingFailReplyQueue).to(bettingExchange)
                .with(RabbitMQConst.ROUTE_FOR_FAIL_BETTING_REPLY);
    }

    @Bean
    Binding bindingBettingFailNSFReplyExchange(Queue bettingFailNSFReplyQueue, TopicExchange bettingExchange) {
        return BindingBuilder.bind(bettingFailNSFReplyQueue).to(bettingExchange)
                .with(RabbitMQConst.ROUTE_FOR_FAIL_NSF_BETTING_REPLY);
    }

    @Bean
    Binding bindingRevokeExchange(Queue revokeQueue, TopicExchange revokeExchange) {
        return BindingBuilder.bind(revokeQueue).to(revokeExchange).with(RabbitMQConst.ROUTE_FOR_REVOKE);
    }

    @Bean
    Binding bindingRevokeReplyExchange(Queue revokeReplyQueue, TopicExchange revokeExchange) {
        return BindingBuilder.bind(revokeReplyQueue).to(revokeExchange).with(RabbitMQConst.ROUTE_FOR_REVOKE_REPLY);
    }

}
